#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import re, sys

page = "http://www.pogdesign.co.uk/cat/download_ics/bf88283d2c124d4a46ad59f527fbae7b"
# page = sys.argv[1]

def fetch_page(page):
	# proxy_handler = urllib2.ProxyHandler({"http" : 'http://127.0.0.1:8087'})
	
	cj = cookielib.CookieJar()
	
	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

	urllib2.install_opener(opener)

	request = ''

	html = opener.open(page, urllib.urlencode(request))
	content = html.read()
	# print content
	content = content.replace('\r\n','$')
	eplist = re.findall(r'BEGIN\:VEVENT\$(.*?)END\:VEVENT',content)
	for ep in eplist:
		# print ep
		m = re.match(r'DTSTART:(.*?)\$.*SUMMARY\:(.*?)\$.*UID:(.*?)\$.*DTSTAMP:(.*?)\$',ep)
		if m:
			print "TI: "+m.group(1)
			print "TV: "+m.group(2)
			print "ID: "+m.group(3)
			print "DT: "+m.group(4)
		print


fetch_page(page)